import axios from './axios'

export const getTags = async () => {
  const ret: any = await axios.get('/api/tag/list')
  return ret.data ? ret.data.tags : []
}

export const delTag = async (id: string) => {
  const ret: any = await axios({
    method: 'POST',
    url: '/api/tag/remove',
    params: { id },
  })
  return ret.data.code ? true : false
}

export const insertTag = async (obj: object) => {
  try {
    const { data } = (await axios({
      method: 'POST',
      url: '/api/tag/insert',
      data: { ...obj },
    })) as any
    return data && data.code ? data : {}
  } catch (error) {
    throw error
  }
}
